package com.kaifamiao.queue;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 对应"双端队列"来说，可以参照其字符串形式来确定哪边是头哪边是尾
 * 1、在Deque中定义的操作队列的方法(不抛出异常)
 *      boolean offerLast( E e )
 *      E peekFirst()
 *      E pollFirst()
 * 2、在Deque中定义的操作队列的方法(可能抛出异常)
 *      void addLast(E e)
 *      E getFirst()
 *      E removeFirst()
 */
public class DequeTest1 {

    public static void main(String[] args) {

        Deque<String> deque = new LinkedList<>();

        /* - - 以 字符串形式 的 左侧 为 队列头 - - */
        deque.offerLast( "唐三藏" ); // deque.offer( "唐三藏" )
        deque.offerLast( "孙悟空" );
        deque.offerLast( "白龙马" );
        System.out.println( deque );

        System.out.println( deque.peekFirst() ); // deque.peek()
        System.out.println( deque );

        System.out.println( deque.pollFirst() ); // deque.poll()
        System.out.println( deque );

        System.out.println( deque.pollFirst() );
        System.out.println( deque );

        System.out.println( deque.pollFirst() );
        System.out.println( deque );

        System.out.println( deque.peekFirst() ); // 因为队列为空所以返回 null
        System.out.println( deque.pollFirst() ); // 因为队列为空所以返回 null

        System.out.println( "- ".repeat( 10 ) );

        deque.addLast( "宋江" ); // deque.add( "宋江" );
        deque.addLast( "李逵" );
        deque.addLast( "吴用" );
        System.out.println( deque );

        System.out.println( deque.getFirst() ); // deque.element()
        System.out.println( deque );

        System.out.println( deque.removeFirst() ); // deque.remove()
        System.out.println( deque );

        System.out.println( deque.removeFirst() );
        System.out.println( deque );

        System.out.println( deque.removeFirst() );
        System.out.println( deque );

        // System.out.println( deque.getFirst() ); // NoSuchElementException
        // System.out.println( deque.removeFirst() ); // NoSuchElementException

    }

}
